package com.dynamic.mybatis.core.utils;

import org.apache.ibatis.builder.BuilderException;
import org.apache.ibatis.session.Configuration;

/**
 * @Description
 * @Author xs
 * @Date 2022/11/1 18:06
 */
public class ConfigurationHelper {

    public static <T> Class<? extends T> resolveClass(String alias, Configuration configuration) {
        if (alias == null) {
            return null;
        }
        try {
            return resolveAlias(alias, configuration);
        } catch (Exception e) {
            throw new BuilderException("Error resolving class. Cause: " + e, e);
        }
    }

    public static <T> Class<? extends T> resolveAlias(String alias, Configuration configuration) {
        return configuration.getTypeAliasRegistry().resolveAlias(alias);
    }
}